package com.zhkj.txg.module.mine.adapter

import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.lib.utils.SpanUtil
import com.zhkj.txg.R
import com.zhkj.txg.module.home.entity.ListEntity
import com.zhkj.txg.module.home.entity.RechargeEntity
import com.zhkj.txg.module.home.entity.ShopCategoryEntity
import com.zhkj.txg.module.mine.entity.MineCateEntity

class RechargeAmountAdapter(val onItemClick: (listEntity: ListEntity) -> Unit) :
    BaseQuickAdapter<ListEntity, BaseViewHolder>(R.layout.item_recharge_amount) {

    var index = 0

    init {
        setOnItemClickListener { adapter, view, position ->
            index = position
            notifyDataSetChanged()
            onItemClick(data[position])
        }
    }

    override fun convert(helper: BaseViewHolder, item: ListEntity) {

        val tvAmount = helper.setText(R.id.tvAmount, SpanUtil.setMoneySymbol(item.payPrice, false))
            .setText(R.id.tvAmountGive, "赠送${SpanUtil.setMoneySymbol(item.sendPrice, false)}")
            .getView<TextView>(R.id.tvAmount)
        val llAmountGroup = helper.getView<LinearLayout>(R.id.llAmountGroup)
        val tvAmountGive = helper.getView<TextView>(R.id.tvAmountGive)
        if (index == getItemPosition(item)) {
            index = getItemPosition(item)
            if (index == 0) {
                onItemClick(data[0])
            }
            tvAmount.setTextColor(context.resources.getColor(R.color.colorMain))
            tvAmountGive.setTextColor(context.resources.getColor(R.color.colorMain))
            llAmountGroup.setBackgroundResource(R.drawable.bg_recharge_select)
        } else {
            tvAmount.setTextColor(context.resources.getColor(R.color.colorLightText))
            tvAmountGive.setTextColor(context.resources.getColor(R.color.colorLightText))
            llAmountGroup.setBackgroundResource(R.drawable.bg_recharge)
        }
    }
}